package change;

import dao.PayrollDatabase;
import dao.imp.GpayrollDatabase;
import domain.Employee;
import exception.EmployeeException;
import transaction.Transaction;

public abstract class ChangeEmployeeTransaction implements Transaction {
    private int empId;
    protected PayrollDatabase payrollDatabase = new GpayrollDatabase();

    public ChangeEmployeeTransaction(int empId) {
        this.empId = empId;
    }

    public int getEmpId() {
        return empId;
    }

    public void setEmpId(int empId) {
        this.empId = empId;
    }

    public abstract void change(Employee employee);

    @Override
    public void execute() throws EmployeeException {
        Employee employee = payrollDatabase.getEmployee(getEmpId());
        if(employee == null) {
            throw new EmployeeException("no such employee. empid=" + getEmpId());
        }
        change(employee);
    }
}
